<?php

class DatabaseResult {
	private $db;
	private $resource;
	
	public function __construct(Database $db, $resource) {
		$this->db       = $db;
		$this->resource = $resource;
	}
	
	public function fetch($fetch_all=false) {
		if ($fetch_all === false) {
			return $this->db->fetch($this->resource);
		} else {
			$rows = array();
			while ($row = $this->db->fetch($this->resource)) {
				$rows[] = $row;
			}
			return $rows;
		}
	}
	
	public function iterator() {
		return new DatabaseIterator($this->db, $this->resource);
	}
}
